﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App.Domain.Contracts;
using App.Domain.Models;
using App.Data;

namespace App.Domain {
    public class UserServices : IUserServices {

        private IRecruiterRepository recruiterRepository;

        public UserServices(IRecruiterRepository recruiterRepository)
        {
            if (recruiterRepository == null) throw new ArgumentNullException("recruiterRepository");
            this.recruiterRepository = recruiterRepository;
        }
        public User GetOrCreateUser(string UserName,string UserPassWord) {
            User user = null;
            try
            {
                user = this.GetUserByClaimedIdentifier(UserName);
                if (user.UserPwd.Equals(UserPassWord))
                {
                    return user;
                }
            }
            catch (Exception ex)
            {
                user = null;
            }

            return user;
        }
        public User GetUserByClaimedIdentifier(string UserName)
        {
            var recruiter = recruiterRepository.GetRecruiter(UserName);

            if (recruiter != null)
            {
                return new User() { 
                
                    UserId=recruiter.Id,
                    DisplayName = recruiter.UserName,
                    UserPwd = recruiter.Password,
                    CompanyId=recruiter.CompanyId,
                };
            }

            return null;

        }
        public void UpdateUser(User updatedUser) {
        }
    }
}
